package servlet;
/**
 * @author ZYS
 * 
 */
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.*;
import dao.*;

/**
 * Servlet implementation class AddThemeServlet
 */
@WebServlet("/AddAnnouncementServlet")
public class AddAnnouncementServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddAnnouncementServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub	

		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		//response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		try {
			String content = request.getParameter("user_name");
			Announcement announcement = new Announcement(content);
			AnnouncementDAO.getInstance().add(announcement);
			request.setAttribute("result_information","添加成功！" );
			request.setAttribute("return_page","AnnouncementServlet" );
			request.setAttribute("return_page_name","公告列表" );
			RequestDispatcher view = request.getRequestDispatcher("result_information.jsp?");
			view.forward(request, response);

		}catch(Exception e){
			out.print("添加失败");
			e.printStackTrace();
		}
	}

}
